import { http } from "../../util/http";
import { userInfo, userInfoUrl } from "../../config";
const dayjs = require('dayjs')
Page({
  data:{
    name: '',
    nickname: '',
    day: '',
  },
  onLaunch: function () {
    console.log('index Launch')
  },
  onLoad: async function (params) {
    console.log('获取用户信息', userInfoUrl)
    http(userInfoUrl, 'POST').then(res => {
      // 1. 判断是否在职员工 company_status  1 - 冻结  2 - 离职  3 - 在职  4 - 退出  5 - 未加入
      // 2. 判断是否完成资料填写 销售头像  销售昵称   sale_avatar  sale_nickname
      if (res.company_status !== 3) {
        tt.navigateTo({
          url: '/page/noauth/noauth',
        });
      } else if (!res.nickname || !res.image) {
        tt.navigateTo({
          url: '/page/info/info',
        });
      }
      const info = JSON.parse(res.info);
      const joinTime = info.join_time;
      const day = dayjs().diff(dayjs(joinTime *1000), 'day')
      this.setData({
        nickname: res.nickname,
        image: res.image,
        name: info.name,
        day
      })
      tt.setStorageSync(userInfo, { nickname: res.nickname, image: res.image, name: info.name })
    }).catch(e => {
      console.log('获取用户信息失败', e)
    }) 
  },
  onShow: function () {
    console.log('page/component/index onShow')
    console.log('-------------')

    // if (!appInstance.globalData.hasLogin) {
    //   console.log('haslogin' + appInstance.globalData.hasLogin)
    //   tt.reLaunch({
    //     url: 'page/API/pages/chat/chat',
    //     success: (res) => {
    //       console.log('relaunch success----' + 'page/API/pages/chat/chat')
    //     }, fail: (res) => {
    //       console.log('relaunch fail----' + 'page/API/pages/chat/chat')
    //     }
    //   });
    // }

  },
  goCommission() {
    tt.navigateTo({
      url: "/page/commission/commission"
    })
  },
  goInfo() {
    tt.navigateTo({
      url: "/page/info/info"
    })
  },
  goSalary() {
    tt.openSchema({
      schema: 'https://applink.feishu.cn/T8JuxIxXydV1'
    })
  },
  goHoliday() {
    tt.openSchema({
      schema: 'https://applink.feishu.cn/T8JuxVWss2HO'
    })
  },
  goApprove() {
    tt.openSchema({
      schema: 'https://applink.feishu.cn/T8Juy4nuDR5N'
    })
  },
  goOkr() {
    tt.openSchema({
      schema: 'https://applink.feishu.cn/T8Juy3BE7d9W'
    })
  },
  goProduct() {
    tt.navigateTo({
      url: "/page/product/product"
    })
  },
  goStock() {
    tt.navigateTo({
      url: "/page/stock/stock"
    })
  },
  goProduct() {
    tt.navigateTo({
      url: "/page/product/product"
    })
  }
})